package nina.yiyou.attendance.s10merge.compute.latepoint

import nina.yiyou.salary.input.config.WorkTimeSheetReader
import spock.lang.Specification

class WorkTimeFinderTest extends Specification {

  List _workTimeCfg

  String _department

  void setup() {
    _workTimeCfg = [
        ['忆游科技/行政中心/财务部'],
        ['忆游科技/行政中心/人事行政部'],
        ['忆游科技/研发中心/研发二组/技术部/服务端'],
        ['忆游科技/研发中心/研发二组'],
        ['忆游科技/研发中心'],
        ['忆游科技'],
    ]
  }

  def "FindTime:精确匹配"() {
    given:
    _department = '忆游科技/研发中心/研发二组'

    when:
    def result = findTime()

    then:
    result.department() == _department
  }

  def "FindTime:匹配最近"() {
    given:
    _department = '忆游科技/研发中心/研发二组/技术部/客户端'

    when:
    def result = findTime()

    then:
    result.department() == '忆游科技/研发中心/研发二组'
  }

  def "FindTime:匹配不到拿默认"() {
    given:
    _department = '忆游科技/美术中心/UI组'

    when:
    def result = findTime()

    then:
    result.department() == '忆游科技'
  }

  WorkTimeSheetReader.Line findTime() {
    def line = { List item ->
      def l = Stub(WorkTimeSheetReader.Line)
      l.department() >> { item[0] }
      return l
    }
    return new WorkTimeFinder(_workTimeCfg.collect(line), _department).findTime()
  }
}
